/**
 * 绘本相关API类型定义
 */

import type {
  LanguageType,
  MediaInfo,
  PageParams,
  ProgressInfo,
  SearchParams,
  TagInfo,
  TimestampInfo,
} from './common'

// 绘本分类
export interface CategoryRespVO extends TimestampInfo {
  id: number
  name: string
  description?: string
  icon?: string
  color?: string
  parentId?: number
  sortOrder: number // 修正字段名：与后端保持一致
  status: number
  language: string // 修正类型：后端使用string而不是LanguageType
  bookCount?: number
  children?: CategoryRespVO[]
}

// 绘本集信息
export interface BookSetRespVO extends TimestampInfo {
  id: number
  title: string
  description?: string
  cover: string // 修复字段名：与后端保持一致，使用 cover 而不是 coverUrl
  categoryId: number
  categoryName?: string
  language: string // 语言类型：en-英文, zh-中文
  difficultyLevel: string // beginner-初级, intermediate-中级, advanced-高级
  ageRange: string // 适合年龄范围，如"3-6岁"
  bookCount: number
  source?: string // 来源/出版社
  isRecommended?: boolean // 是否推荐
  totalPages?: number
  estimatedReadingTime?: number // 预计阅读时长（分钟）
  tags?: TagInfo[]
  author?: string
  publisher?: string
  publishDate?: string
  isbn?: string
  price?: number
  originalPrice?: number
  status: number
  sort: number
  viewCount: number
  favoriteCount: number
  readCount: number
  rating?: number
  ratingCount?: number
  // 用户相关状态
  isFavorited?: boolean
  readingProgress?: ProgressInfo
  lastReadTime?: string
}

// 绘本集详情响应
export interface BookSetDetailRespVO extends BookSetRespVO {
  books: PictureBookRespVO[]
  relatedBookSets?: BookSetRespVO[]
  reviews?: BookSetReview[]
}

// 绘本集评价
export interface BookSetReview {
  id: number
  userId: number
  userNickname: string
  userAvatar?: string
  rating: number
  content: string
  images?: string[]
  likeCount: number
  isLiked?: boolean
  createTime: string
}

// 阅读状态信息
export interface ReadStatusVO {
  isRead: boolean
  readCount: number
  lastReadAt?: string
  readProgress: number
  lastPage?: number
  readingTime?: number
}

// 绘本信息
export interface PictureBookRespVO extends TimestampInfo {
  id: number
  bookSetId: number
  bookSetTitle?: string
  title: string
  description?: string
  cover: string // 修复字段名：与后端保持一致，使用 cover 而不是 coverUrl
  language: LanguageType
  difficulty: string
  pages: number // 修复字段名：与后端保持一致，使用 pages 而不是 pageCount
  estimatedReadingTime?: number
  tags?: TagInfo[]
  author?: string
  illustrator?: string
  narrator?: string
  status: number
  sortOrder: number // 修复字段名：与后端保持一致，使用 sortOrder 而不是 sort
  viewCount: number
  favoriteCount: number
  readCount: number
  // 用户相关状态
  isFavorited?: boolean
  readingProgress?: ProgressInfo
  lastReadTime?: string
  isCompleted?: boolean
  readStatus?: ReadStatusVO
}

// 绘本详情响应
export interface PictureBookDetailRespVO extends PictureBookRespVO {
  pageList?: BookPageRespVO[] // 后端返回的页面列表字段名
  pages?: BookPageRespVO[] // 兼容字段
  audioResources?: AudioResourceRespVO[]
  userRecordings?: UserRecordingRespVO[]
  relatedBooks?: PictureBookRespVO[]
}

// 绘本页面信息
export interface BookPageRespVO extends TimestampInfo {
  id: number
  bookId: number
  pageNumber: number
  imageUrl: string
  imageWidth?: number
  imageHeight?: number
  textContent?: string
  chineseTranslation?: string
  textLanguage?: string
  officialAudioUrl?: string
  userAudioUrl?: string
  audioDuration?: number
  readingDifficulty?: string
  keyWords?: string[]
  translation?: string
  pinyin?: string
  vocabulary?: VocabularyItem[]
  sort?: number
  status?: number
}

// 词汇项
export interface VocabularyItem {
  word: string
  pronunciation?: string
  meaning: string
  example?: string
  audioUrl?: string
}

// 音频资源
export interface AudioResourceRespVO extends TimestampInfo, MediaInfo {
  id: number
  bookId?: number
  pageId?: number
  type: string // official-官方, user-用户, ai-AI生成
  title?: string
  description?: string
  language: LanguageType
  speaker?: string
  quality: string // high-高质量, medium-中等, low-低质量
  status: number
  playCount: number
  likeCount: number
  isLiked?: boolean
}

// 用户配音记录
export interface UserRecordingRespVO extends TimestampInfo, MediaInfo {
  id: number
  userId: number
  userNickname?: string
  userAvatar?: string
  bookId: number
  pageId?: number
  title?: string
  description?: string
  qualityScore?: number
  status: string // draft-草稿, published-已发布, deleted-已删除
  isPublic: boolean
  playCount: number
  likeCount: number
  commentCount: number
  isLiked?: boolean
  isFollowingUser?: boolean
}

// 绘本集搜索参数
export interface BookSetSearchParams extends SearchParams {
  categoryId?: number
  difficulty?: string
  ageRange?: string
  language?: LanguageType
  minBookCount?: number
  maxBookCount?: number
  hasAudio?: boolean
  isFree?: boolean
  minRating?: number
}

// 绘本搜索参数
export interface BookSearchParams extends SearchParams {
  bookSetId?: number
  categoryId?: number
  difficulty?: string
  language?: LanguageType
  hasAudio?: boolean
  isCompleted?: boolean
  minPages?: number
  maxPages?: number
}

// 推荐绘本集参数
export interface RecommendedBookSetsParams extends PageParams {
  type?: string // featured-精选, new-最新, popular-热门, personalized-个性化
  categoryId?: number
  lang?: string // 语言类型：en-英文, zh-中文
  userId?: number
}

// 注意：RecentReadingRespVO 类型已移至 record.ts 模块

// 今日阅读统计
export interface TodayReadingRespVO {
  totalBooks: number
  completedBooks: number
  totalReadingTime: number // 分钟
  booksRead: RecentReadingRespVO[]
  readingGoal?: number
  goalProgress?: number
}

// 阅读历史参数
export interface ReadingHistoryParams extends PageParams {
  language?: LanguageType
  categoryId?: number
  isCompleted?: boolean
  startDate?: string
  endDate?: string
}

// 收藏参数
export interface FavoriteParams extends PageParams {
  type: 'book_set' | 'book' | 'recording'
  categoryId?: number
  language?: LanguageType
}

// 收藏操作请求
export interface FavoriteOperationReqVO {
  targetId: number
  targetType: 'book_set' | 'book' | 'recording'
}

// 收藏状态响应
export interface FavoriteStatusRespVO {
  targetId: number
  targetType: string
  isFavorited: boolean
  favoriteTime?: string
}

// 批量收藏状态检查请求
export interface BatchFavoriteCheckReqVO {
  items: Array<{
    targetId: number
    targetType: string
  }>
}

// 绘本集创建请求（管理员功能）
export interface BookSetCreateReqVO {
  title: string
  description?: string
  coverUrl: string
  categoryId: number
  language: LanguageType
  difficulty: string
  ageRange: string
  tags?: string[]
  author?: string
  publisher?: string
  publishDate?: string
  isbn?: string
  price?: number
  originalPrice?: number
  sort?: number
}

// 绘本创建请求（管理员功能）
export interface PictureBookCreateReqVO {
  bookSetId: number
  title: string
  description?: string
  coverUrl: string
  language: LanguageType
  difficulty: string
  tags?: string[]
  author?: string
  illustrator?: string
  narrator?: string
  sort?: number
}
